package com.bawei.module_vip.ui.adapter

import android.view.LayoutInflater
import android.view.ViewGroup

import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.ListAdapter
import androidx.recyclerview.widget.RecyclerView
import com.bawei.module_vip.data.VipItem
import com.bawei.module_vip.databinding.FragmentVipBinding


class VipAdapter (
  private val onEditClick:(VipItem) ->Unit,
  private val onDeleteClick:(VipItem)->Unit
): ListAdapter<VipItem, VipAdapter.VipViewHolder>(VipDiffCallback()) {
    override fun onCreateViewHolder(parent : ViewGroup,viewType:Int):VipViewHolder{
        val binding = FragmentVipBinding.inflate(
            LayoutInflater.from(parent.context),
            parent,
            false
        )
        return VipViewHolder(binding)
    }

    override fun onBindViewHolder(holder: VipViewHolder, position: Int) {
        val car = getItem(position)
        holder.bind(car)
    }

    class VipViewHolder(val binding:FragmentVipBinding):RecyclerView.ViewHolder(binding.root){
        fun bind(vip:VipItem){
            binding.tvDj.text = vip.membershipLevel
            binding.tvTime.text = vip.registrationDate
        }
    }
}
class VipDiffCallback:DiffUtil.ItemCallback<VipItem>(){
    override fun areItemsTheSame(oldItem: VipItem, newItem: VipItem): Boolean {
        return oldItem.id == newItem.id
    }
    override fun areContentsTheSame(oldItem: VipItem, newItem: VipItem): Boolean {
        return oldItem == newItem
    }


}